package servlet;

import com.alibaba.fastjson.JSONArray;
import service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
/**
 *2022.3.16测试完成，由李红玉编写
 *显示学生表
 */
@WebServlet(name = "StudentAllshowServlet", value = "/StudentAllshowServlet")
public class StudentAllshowServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        resp.setContentType("text/html; charset=utf-8");
        StudentService studentService=new StudentService();
        JSONArray jsonArray=null;
        try {
            jsonArray=studentService.allShow();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        PrintWriter out=resp.getWriter();
        out.println(jsonArray.toJSONString());
    }
}
